﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Domain.IRepository.BOM;
using FriendStar.Repository.BOM;

namespace FriendStar.Application.BOM
{
    /// <summary>
	/// 数据视图 V_PLM_GG_WGGGCP 对应的数据应用功能类。
	/// </summary>
    public class V_PLM_GG_WGGGCPApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");

        private IV_PLM_GG_WGGGCPRepository service = new V_PLM_GG_WGGGCPRepository();

        public List<V_PLM_GG_WGGGCPEntity> GetList(Pagination pagination, string keyword, string number, string name, string memo, string begin, string end)
        {
            var expression = ExtLinq.True<V_PLM_GG_WGGGCPEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.LXD.Contains(keyword));
            }
            if (!string.IsNullOrEmpty(memo))
            {
                expression = expression.And(t => t.SM.Contains(memo));
            }
            
            string extWhere = string.Empty;
            if (!string.IsNullOrEmpty(number))
            {
                if (!string.IsNullOrEmpty(extWhere))
                {
                    extWhere += " and ";
                }
                extWhere += string.Format("(N_TH like '%{0}%' or O_TH like '%{0}%')", number);
            }
            if (!string.IsNullOrEmpty(name))
            {
                if (!string.IsNullOrEmpty(extWhere))
                {
                    extWhere += " and ";
                }
                extWhere += string.Format("(N_MC like '%{0}%' or O_MC like '%{0}%')", name);
            }
            if (!string.IsNullOrEmpty(begin))
            {
                if (!string.IsNullOrEmpty(extWhere))
                {
                    extWhere += " and ";
                }
                extWhere += "cast(FCreateDate as datetime) >= '" + begin + "'";
            }
            if (!string.IsNullOrEmpty(end))
            {
                if (!string.IsNullOrEmpty(extWhere))
                {
                    extWhere += " and ";
                }
                extWhere += "cast(FCreateDate as datetime) <= '" + end + "'";
            }

            return service.FindList(expression, pagination, extWhere);
        }
    }
}